<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var a = (b = 10);
      (function () {
        var a = (b = 20);
      })();
      console.log(b);

      // var a;  显示声明
      // b = 10; 隐式声明
      // a = b;  赋值
      // (function(){
      //     var a;
      //     b = 20 ; 隐式声明变量无论在全局还是在函数中都是全局变量！
      //     a = b;

      // })()
      // console.log(b)

      var x = 5;
      function haha() {
        console.log(x);
        var x = 10;
        console.log(x);
      }
      haha();
      console.log(x)

      变量提升
      把变量和函数提前到作用域顶端
      var x;
      function haha(){
        var x;
        console.log(x);  //局部函数，就近原则，先找局部x
        x = 10;
        console.log(x)
      }
      x = 5;
      console.log(x)  //打印全局x
    </script>
  </body>
</html>
